package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.StudentDao;
import com.itheima.edu.info.manager.domain.Student;

public class StudentService {
    private StudentDao studentDao = new StudentDao();

    public boolean addStudent(Student stu) {
        return studentDao.addStudent(stu);
    }

    public boolean isExits(String id) {
        Student[] students = studentDao.finAllStudent();
        for (Student student : students) {
            if (student != null && id.equals(student.getId())) {
                return true;
            }
        }
        return false;
    }

    public Student[] finAllStudent() {
        Student[] students = studentDao.finAllStudent();
        boolean flag =false;
        for (Student student : students) {
            if (student != null) {
                flag=true;
            }
        }
        if (flag ) {
            return studentDao.finAllStudent();
        }else {
            return null;
        }
    }

    public void deleteStudentById(String id) {
        studentDao.deleteStudentById(id);
    }

    public void updateStudentById(Student stu,String id) {
        studentDao.updateStudentById(stu,id);
    }
}
